<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
<link type="text/css" rel="stylesheet" href="<%=contextPath %>/static/bootstrap-fileinput/css/fileinput.css" />
<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/fileinput.js"></script>
<script type="text/javascript" src="<%=contextPath %>/static/bootstrap-fileinput/js/locales/zh.js"></script>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post"
			enctype="multipart/form-data">
			<input type="hidden" class="form-control" id="taskId" name="taskId" value="${taskId }"/><!--任务主表id  -->
			<input type="hidden" class="form-control" id="status" name="status" value="${status }"/>
			<c:if test="${status eq 2 || status eq 5 }">
			<div class="form-group">
				<label class="col-sm-3 control-label">完成时间：</label>
				<div class="col-sm-8">
				   <input type="text" class="form-control"  id="finishTime" name="finishTime"  onclick="WdatePicker({startDate:'%y-%M-%d %h:%m:%s',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})" readonly="readonly"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">完成事项：</label>
				<div class="col-sm-8">
				   <textarea rows="3" cols="3" class="form-control" id="completes" name="completes" ></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">耗时：</label>
				<div class="col-sm-8">
				   <input type="text" class="form-control"  id="duration" name="duration"  placeholder="请输入多少小时" onblur="isInteger('duration',this.value)"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">附件：</label>
				<div class="col-sm-8 form-inline">
					<input type="hidden" class="form-control" id="attachment1" name="attachment" />
					<input type="file" name="file" id="attachment" multiple>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" />
				</div>
			</div>
			</c:if>
			<c:if test="${status eq 3 || status eq 4 }">
			<div class="form-group">
				<label class="col-sm-3 control-label">原因：</label>
				<div class="col-sm-8">
				   <textarea rows="3" cols="3" class="form-control" id="completes" name="completes" ></textarea>
				</div>
			</div>
			</c:if>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
	
    $(function () {
    	initFileInput("attachment");
        $("#sub").click(function () {
        	//批量验证表单非空
        	var arr=new Array(
        	  new Array('type','事项类别未填写!'),
        	  new Array('completes','完成事项未填写!')
        	)
        	  for(var i=0;i<arr.length;i++){
	        	  if($("#"+arr[i][0]).val()==''){
	        		  $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		  $("#"+arr[i][0]).focus();
	  				return;
	  			}
        	  }
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/taskCompletion/add',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
	});
    function initFileInput(ctrlName) {
        var control = $('#' + ctrlName);
        var fileurl="";
        control.fileinput({
        language : 'zh',
        uploadUrl : "<%=contextPath%>/upload/insert",
        //allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
        uploadAsync: true, //默认异步上传
        showUpload: false, //是否显示上传按钮
        showRemove : false, //显示移除按钮
        showPreview : true, //是否显示预览
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        dropZoneEnabled: false,//是否显示拖拽区域
        maxFileSize : 5000,
        maxFileCount: 20, //表示允许同时上传的最大文件个数
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on('filebatchselected', function (event, files) {//选中文件事件  
        $(this).fileinput("upload");  
    }).on("fileuploaded", function(e, data) {
        var res = data.response;
        fileurl += res.success+",";
        var num=1;
        $('#' + ctrlName+num).attr("value", fileurl);
    })
    }
	</script>
</body>
</html>